package com.example.zhu.Mapper;

import com.example.zhu.dto.IncomeVo;
import com.example.zhu.dto.MyPage;
import com.example.zhu.dto.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("insert into orders (id,room_name,create_time,update_time,status) VALUES (#{id},#{roomName},#{createTime},#{updateTime},#{status})")
    void insert(Order order);
    @Select("select * from orders where id=#{orderId}")
    Order selectByid(String orderId);
    @Update("update orders set update_time=#{updateTime} where id=#{id}")
    void updateNickname(Order order);
    @Update("update orders set status=#{status} ,update_time=#{updateTime} where id=#{id}")
    void updateStatus(Order order);
    @Update("update orders set pay=#{pay} ,update_time=#{updateTime},status=#{status} ,pay_method=#{payMethod},msg=#{msg} where id=#{id}")
    void updatePay(Order order);
    @Select("select * from orders where room_name like #{roomName} and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_time)  ORDER BY create_time desc")
    List<Order> getRoomNameList(String roomName);
    @Select("select * from orders where status like #{status} and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_time)  ORDER BY create_time desc")
    List<Order> getStatusList(String status);

    @Select("select * from orders ORDER BY create_time desc limit #{min}, #{max}")
    List<Order> getAllList(MyPage page);
    @Select("select count(id) from orders")
    int getAllListCount();
    @Select("select * from orders where create_time>=#{beginTime} and create_time<=#{endTime} ORDER BY create_time desc")
    List<Order> getDateList(Date beginTime, Date endTime);
    @Select("SELECT DATE(create_time) AS date, sum(pay) AS num FROM orders WHERE `status` = 1  and create_time>=#{date} GROUP BY date ORDER BY date;")
    List<IncomeVo> selectNumList( Date date);
    @Select("SELECT DATE(create_time) AS date, count(pay) AS num FROM orders WHERE `status` = 1  and create_time>=#{date} GROUP BY date ORDER BY date;")
    List<IncomeVo> selectCountList(Date date);
    @Select("select t1.* from orders as t1 , order_project as t2 where t1.id=t2.order_id and t2.nickname like #{nicknames} and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_time)  ORDER BY create_time desc;")
    List<Order> getNickNameList(String nicknames);
}
